Linux
=linux= reference doc *http://linux.vbird.org/ screen 1) screen -L -d -RR -S buildmaster; -> Start a screen as the buildmaster user; 2) screen -x; -> resume to last screen; 3) ctrl-a d; -> quit current screen, Detached; 4) ctrl-a 1/2/3/4...; -> switch in different window; 5) ctrl-a c; -> Create a new window in the screen; 6) ctrl-a shift-A; -> Change the window name in the screen; 7) ctrl-a " -> list all window 8) ctrl-a [ + arrow key -> copy mode, can roll screen, press "Esc" exit from copy mode 10)ctrl-a + K -> kill current window 11)ctrl-a + ctrl-n -> move to next window 12)ctrl-a + ctrl-Backspace -> move to previous window screen guide : http://magazine.redhat.com/2007/09/27/a-guide-to-gnu-screen/ vi tips check disk usage * check disk usage ~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 107G 17G 85G 17% / tmpfs 974M 4.7M 969M 1% /dev/shm * check folder usage ~$ du -sh * 192K Desktop 40K Documents 810M Downloads 57M jmeter-2.3.4 12K memcached 4.0K Music lsof //Check specify process open files count shell>sudo /usr/sbin/lsof -p 16508 |wc -l //查找监听 3306 port 的 process shell>lsof -i:3306 ssh no password login * enter the ~/.ssh directory .ssh$ ll total 24 -rw------- 1 iphone iphone 406 Jun 29 2010 authorized_keys -rw------- 1 iphone iphone 1679 Jun 29 2010 id_rsa -rw-r--r-- 1 iphone iphone 406 Jun 29 2010 id_rsa.pub -rw-r--r-- 1 iphone iphone 11773 Dec 14 17:00 known_hosts * id_rsa and id_rsa.pub were create by command ssh-keygen -t rsa. id_rsa.pub is your public key, put it's content to the remote machine ~/.ssh/authorized_keys then you can ssh without password. .ssh$ssh-keygen -t rsa * know_hosts is the machine list, you ssh connect from. * http://hi.baidu.com/zengzhaonong/blog/item/1b444eda858bc3dab6fd48a6.html - a doc from baidu check system info print operation system name shell>uname -a ~$ uname -a Linux bjsit1iphonedev01 2.6.33.3-85.fc13.i686.PAE #1 SMP Thu May 6 18:27:11 UTC 2010 i686 i686 i386 GNU/Linux check linux release version shell>cat /etc/redhat-release ~$ cat /etc/redhat-release Fedora release 13 (Goddard) rpm //check install rpm name shell>rpm -qa|grep -i tib //查看rpm 包的 info 信息 shell> rpm -pqi mysql.rpm //查看rpm 包的 目标安装路径 shell> rpm -pql mysql.rpm //查询 rpm 包的安装位置 shell> sudo rpm -ql libevent //安装rpm 包 shell> rpm -ivh mysql.rpm //安装/升级 rpm 包 shell>rpm -Uvh foo.rpm //删除 rpm 包 shell> rpm -e mysql.rpm //打开 rpm 包，查看内容 shell> rpm2cpio some.rpm | cpio -div add sudo privilege su root chmod +w /etc/sudoers echo '${username} ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers chmod -w /etc/sudoers exit *check current user sudo privilege info shell>sudo -l change linux hostname vi /etc/sysconfig/network vi /etc/hosts reboot system telnet tips telent telnet 10.33.133.62 port Connected to produsx-iphoneapp-02.g3.reuters.com (10.33.133.62). Escape character is '^]'. ctrl + ] // 结束http 消息 ^] telnet> quit check dns host -t TXT qa2-iphoneapp-info host -i qa2-admindb-vip VNC settings set vnc server with display rate, edit file /etc/sysconfig/vncservers shell>sudo vi /etc/sysconfig/vncservers VNCSERVERS="1:iphone" VNCSERVERARGS1="-geometry 1280x800" check your shell shell> echo $SHELL /bin/bash cron tab *http://www.adminschoice.com/crontab-quick-reference - crontab ref cron file in folder, use user name as file name /var/spool/cron crontab -u user -l ctrl + r ## search history command shell> ctrl + r killall kill a batch of process with same name pattern. ~$ sudo killall cronInvoker.sh zip & unzip * 解压 .tar.gz shell>tar -zxvf file.tar.gz * unzip to specify folder (/tmp) shell>tar -zxvf file.tar.gz -C /tmp * unzip part contents (abc/mm/*) to specify folder (/tmp) shell>tar -zxvf file.tar.gz -C /tmp abc/mm/* * 解压 .tar.bz2 shell>tar -jxvf file.tar.bz2 * 打包 tar , 不压缩 shell>tar -cvf /tmp/file.tar /tmp/folder1 * 压缩 .tar.gz shell>tar -zcvf /tmp/file.tar.gz /tmp/folder2 * 压缩 .tar.bz2 shell>tar -jcvf /tmp/file.tar.bz2 /tmp/folder3 * http://coolszy.iteye.com/blog/564459 - tar ref file privilege -rwxrwxrwx user/group/others r:4, w:2, x:1 r + w + x = 7 r + w = 6 r + x = 5 * 修改用户所属 group , chgrp shell>chgrp -R users dirnmae/filename * 修改文件拥有者 chown shell> chown -R 用户 dirname/filename shell> chown -R 用户:组 install.log * 修改文件的权限 chmod //-R 是递归 recursive 数字权限法 shell> chmod -R 777 dirname/filename u,g,o,a 权限法， + (加入)， - (减去)， = (设置) shell> chmod u=rwx,go=rx filename shell> chmod a+w filename shell> chmod a-w filename pwd shell> pwd //显示当前目录 shell> pwd -P //显示当前目录，将 soft link 转为真实目录 mkdir shell> mkdir -m 711 dir1 //建立目录，并指定目录的 r,w,x 权限 shell> mkdir -p dir2/child //建立多级目录 cat //cat 将文件输出到标准输出 shell>cat .bash_profile //将 file1 , file2 的内容合并放入 file3 shell> cat file1 file2 > file3 // 将 foo.txt 内容追加到 love.txt 之后 shell> cat foo.txt >> love.txt ls * ls 列出的文件类型 [ d ]是目录 [ - ]是文件 [ l ]表示link file(软链接) [ b ]表示随机读取的存储设备； [ c ]表示顺序读取设备，如键盘、鼠标 /etc/bashrc * /etc/bashrc 是全局的环境配置文件 一般引用顺序 /etc/basrc --> ~/.basrc --> ~/.bash_profile set path variable shell >vi /home/${user}/.bash_profile add to path variable following entries: :/usr/bin:/bin:/sbin:/usr/sbin:/usr/local/bin: install jdk download a new version jdk ,such as jdk-6u16-linux-i586.bin shell >sudo chmod a+x jdk-6u16-linux-i586.bin shell >./jdk-6u16-linux-i586.bin shell >sudo mkdir /usr/java shell >sudo mv jdk1.6.0_16 /usr/java/jdk1.6.0_16 add /usr/java/jdk1.6.0_16/bin to path shell >vi ~/.bash_profile create soft link for java and javac shell >sudo ln -s /usr/java/jdk1.6.0_16/bin/java /usr/bin/java shell >sudo ln -s /usr/java/jdk1.6.0_16/bin/javac /usr/bin/javac shell >java -version install maven download apache-maven-2.2.1-bin.zip shell >unzip apache-maven-2.2.1-bin.zip shell >mv apache-maven-2.2.1 ~/maven-2.2.1 # add maven/bin to .bash_profile # export JAVA_HOME parameter shell >mvn -version Apache Maven 2.2.1 (r801777; 2009-08-07 03:16:01+0800) Java version: 1.6.0_16 Java home: /usr/java/jdk1.6.0_16/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux" version: "2.6.27.5-117.fc10.i686" arch: "i386" Family: "unix" install ant download apache-ant-1.7.1-bin.tar.gz shell >tar -zxvf apache-ant-1.7.1-bin.tar.gz shell >mv apache-ant-1.7.1 ~/ant-1.7.1 ＃add ant/bin to .bash_profile shell >ant -version Apache Ant version 1.7.1 compiled on June 27 2008 more more 分页显示 shell>ls -al | more shell> cat foo.txt | more /etc/shells 系统可用的 shell 在 /etc/shells 文件中记录 localhost:bin lokvin$ cat /etc/shells # List of acceptable shells for chpass(1). # Ftpd will not allow users to connect who are not using # one of these shells. /bin/bash /bin/csh /bin/ksh /bin/sh /bin/tcsh /bin/zsh .bash_history 你所输入过的 命令，记录在文件 ~/.bash_history 中 alias alias 设置别名，可以设置在文件 ~/.bash_profile 中 直接输入 alias ，查询当前可用别名 alias ll='ls -al' ps aux | grep #查找类似名称的 process shell> ps aux | grep firefox common install from source *一般的从源码安装步骤 #--with-prefix 指定安装位置 shell> ./configure --with-prefix=/usr/local/dirname shell> make shell> make install